package com.liz.lizrpccore.enums;

import com.liz.lizrpccore.beans.proxys.base.LizAbstractProxy;
import com.liz.lizrpccore.beans.proxys.netty.LizNettyProxy;
import com.liz.lizrpccore.beans.proxys.redis.LizRedisProxy;
import com.liz.lizrpccore.core.providers.LizPrcProvider;
import com.liz.lizrpccore.core.providers.netty.LizRpcNettyProvider;
import com.liz.lizrpccore.core.providers.redis.LizRpcRedisProvider;

public enum ProxyTypeEnum {
    REDIS("redis",new LizRedisProxy(),new LizRpcRedisProvider()),
    NETTY("netty",new LizNettyProxy(),new LizRpcNettyProvider());

    private String type;
    private LizAbstractProxy proxy;
    private LizPrcProvider lizPrcProvider;

    ProxyTypeEnum(String type, LizAbstractProxy proxy,LizPrcProvider lizPrcProvider) {
        this.type = type;
        this.proxy = proxy;
        this.lizPrcProvider = lizPrcProvider;
    }

    public String getType() {
        return type;
    }

    public LizAbstractProxy getProxy() {
        return proxy;
    }

    public LizPrcProvider getLizPrcProvider() {
        return lizPrcProvider;
    }

    public static LizAbstractProxy getProxy(String type){
        for (ProxyTypeEnum value : ProxyTypeEnum.values()) {
            if (value.type.equals(type)){
                return value.proxy;
            }
        }
        return REDIS.proxy;
    }

    public static LizPrcProvider getProvider(String type){
        for (ProxyTypeEnum value : ProxyTypeEnum.values()) {
            if (value.type.equals(type)){
                return value.lizPrcProvider;
            }
        }
        return REDIS.lizPrcProvider;
    }
}
